package cn.globalph.housekeeper.ui

import android.content.Intent
import android.os.Bundle
import android.util.TypedValue
import androidx.appcompat.app.AppCompatActivity
import cn.globalph.housekeeper.ui.dialog.LoadingViewDialog
import cn.globalph.housekeeper.ui.login.LoginActivity
import cn.globalph.housekeeper.utils.SystemUtils
import com.umeng.analytics.MobclickAgent

abstract class BaseActivity : AppCompatActivity(){
    private lateinit var loadingDialog:LoadingViewDialog

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        loadingDialog = LoadingViewDialog()
        initView()
    }

    override fun onResume() {
        super.onResume()
        MobclickAgent.onResume(this)
    }

    override fun onPause() {
        super.onPause()
        MobclickAgent.onPause(this)
    }

    abstract fun initView()

    open fun tokenInvalid(){
        TT("认证失败，请重新登陆")
        startActivity(Intent(getContext(),LoginActivity::class.java))
        finish()
    }

    fun TT(msg:String){
        SystemUtils.TT(this,msg)
    }

    fun showLoading(){
        loadingDialog.show(supportFragmentManager,"loading")
    }

    fun dismissLoading(){
        loadingDialog.dismiss()
    }

    fun getContext() = this

    fun dp2px(dpVal: Float): Int {
        return TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP,
            dpVal,
            resources.displayMetrics
        ).toInt()
    }

}